//
//  GQMusicPlayViewController.m
//  TingMusic
//
//  Created by sunny on 16/4/25.
//  Copyright © 2016年 sunny. All rights reserved.
//

#import "GQMusicPlayViewController.h"
#import <AVFoundation/AVAudioPlayer.h>

@interface GQMusicPlayViewController ()
@property (nonatomic, strong)AVAudioPlayer *player;
/** 记录播放状态 */
@property (nonatomic, assign)BOOL isPlaying;
@property (weak, nonatomic) IBOutlet UIButton *prePlayButton;
@property (weak, nonatomic) IBOutlet UIButton *nextPlaybutton;
@property (weak, nonatomic) IBOutlet UIButton *playbutton;
@end

@implementation GQMusicPlayViewController
- (IBAction)backButtonClick {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //创建播放器
    
    NSURL *musicURL = [[NSBundle mainBundle] URLForResource:@"泡沫.mp3" withExtension:nil];
    
    self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:nil];
    
    //准备
    [self.player prepareToPlay];
    
}

- (IBAction)playButton:(UIButton *)sender {
    
    if (self.isPlaying) {
        [self.player pause];
        
        [self.playbutton setImage:[UIImage imageNamed:@"playbar_nextbtn_nomal"] forState:UIControlStateNormal];
        [self.playbutton setImage:[UIImage imageNamed:@"playbar_nextbtn_click"] forState:UIControlStateNormal];
        
        self.isPlaying = NO;
        return;
    }
    
//    播放音乐
    [self.player play];

    self.isPlaying = YES;
    
    [self.playbutton setImage:[UIImage imageNamed:@"playbar_pausebtn_nomal"] forState:UIControlStateNormal];
    [self.playbutton setImage:[UIImage imageNamed:@"playbar_pausebtn_click"] forState:UIControlStateNormal];

    
}


@end
